Dart BigInt operator unary-
Syntax & Examples


BigInt.operator unary- operator

The `unary-` operator returns the negative value of this BigInt.


Syntax of BigInt.operator unary-

The syntax of BigInt.operator unary- operator is:

operator unary-() → BigInt

This operator unary- operator of BigInt return the negative value of this integer.



✐ Examples

1 Get negative value of positive BigInt

In this example,

  1. We define a positive BigInt num with a value of 10.
  2. We use the `unary-` operator to get the negative value of num.
  3. We print the negative value to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(10);
  BigInt negative = -num;
  print('Negative value: $negative');
}

Output

Negative value: -10

2 Get negative value of negative BigInt

In this example,

  1. We define a negative BigInt num with a value of -10.
  2. We use the `unary-` operator to get the negative value of num.
  3. We print the negative value to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(-10);
  BigInt negative = -num;
  print('Negative value: $negative');
}

Output

Negative value: 10

Summary

In this Dart tutorial, we learned about operator unary- operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.